#{extends 'backend_main.html' /}
#{set title:'后台管理' /}
    <div class="x-body">
        <form class="layui-form">
            <input type="hidden" id="id" name="id" value="${item?.id}">
            <input type="hidden" id="filename" name="filename" value="${item?.filename}">
          <div class="layui-form-item">
              <label for="customer_name" class="layui-form-label">
                  <span class="x-red">*</span>客户姓名
              </label>
              <div class="layui-input-inline">
                  <input type="text" id="customer_name" name="customer_name" required="" lay-verify="required|customer_name" autocomplete="off" class="layui-input"
                         value="${item?.customer_name}">
              </div>
          </div>
            <div class="layui-form-item">
                <label for="customer_name" class="layui-form-label">
                    <span class="x-red">*</span>图片
                </label>
                <div class="layui-input-inline">
                    <button type="button" class="layui-btn" id="uploadImg">
                        <i class="layui-icon">&#xe67c;</i>上传图片
                    </button>
                </div>
                <div class="layui-input-inline">
                    #{if item!=null}
                        <img src="/FileController/images?uuid=${item?.filename}" width="200" height="100" id="imgView" name="imgView" onclick="layerPhotos({src:this.src})">
                    #{/if}
                    #{else }
                        <img src="" width="200" height="100" id="imgView" name="imgView" onclick="layerPhotos({src:this.src})" />
                    #{/else}
                </div>
            </div>
            <div class="layui-form-item">
                <label for="customer_name" class="layui-form-label">
                    <span class="x-red">*</span>下单时间
                </label>
                <div class="layui-input-inline">
                    <input class="layui-input" placeholder="下单时间" name="buy_date" id="buy_date" value="${item?.getBuy_date()}">
                </div>
            </div>
            <div class="layui-form-item">
                <label for="customer_name" class="layui-form-label">
                    <span class="x-red">*</span>单价
                </label>
                <div class="layui-input-inline">
                    <input class="layui-input" placeholder="￥" name="single_price" id="single_price" value="${item?.single_price}">
                </div>
            </div>
            <div class="layui-form-item">
                <label for="customer_name" class="layui-form-label">
                    <span class="x-red">*</span>购买张数
                </label>
                <div class="layui-input-inline">
                    <input class="layui-input" placeholder="购买张数" name="all_count" id="all_count" value="${item?.all_count}">
                </div>
            </div>
            <div class="layui-form-item">
                <label for="customer_name" class="layui-form-label">
                    <span class="x-red">*</span>总金额
                </label>
                <div class="layui-input-inline">
                    <input class="layui-input" placeholder="￥" name="sum_price" id="sum_price" value="${item?.sum_price}">
                </div>
            </div>
          <div class="layui-form-item">
              <label for="pay_status" class="layui-form-label">
                  <span class="x-red">*</span>付款状态
              </label>
              <div class="layui-input-inline">
                  #{select 'pay_status', value:item?.pay_status, id:'pay_status', class:"valid"}
                      #{option 0}待付款#{/option}
                      #{option 1}已付款#{/option}
                  #{/select}
              </div>
          </div>
            <div class="layui-form-item">
                <label for="customer_name" class="layui-form-label">
                    <span class="x-red">*</span>客户级别
                </label>
                <div class="layui-input-inline">
                    <input class="layui-input" placeholder="客户级别" name="customer_level" id="customer_level" value="${item?.customer_level}">
                </div>
            </div>
            <div class="layui-form-item">
                <label for="customer_name" class="layui-form-label">
                    <span class="x-red">*</span>客户来源
                </label>
                <div class="layui-input-block">
                    <input class="layui-input" placeholder="客户来源" name="customer_source" id="customer_source" value="${item?.customer_source}">
                </div>
            </div>
          <div class="layui-form-item layui-form-text">
              <label for="common" class="layui-form-label">
                  备注
              </label>
              <div class="layui-input-block">
                  <input class="layui-input" placeholder="请输入备注内容" name="common" id="common" value="${item?.common}">
              </div>
          </div>
          <div class="layui-form-item">
              <label for="L_repass" class="layui-form-label">
              </label>
              <button  class="layui-btn" lay-filter="add" lay-submit="">
                  提交
              </button>
          </div>
      </form>
    </div>
    <script>
        layui.use(['form','layer','upload','laydate'], function(){
          var $ = layui.jquery;
          var form = layui.form,layer = layui.layer;
          var upload = layui.upload;
            var laydate = layui.laydate;
            //执行一个laydate实例
            laydate.render({
                elem: '#buy_date' //指定元素
                ,type: 'date'
            });
            //执行实例
            upload.render({
                elem: '#uploadImg' //绑定元素
                ,url: '/FileController/uploadImage' //上传接口
                ,field:"imgFile"
                ,done: function(res){
                    //上传完毕回调
                    $("#filename").val(res.filename);
                    $("#imgView").attr("src","/FileController/images?uuid=" + res.filename);
                    console.log(JSON.stringify(res));
                }
            });
              //自定义验证规则
              form.verify({
                  customer_name: function(value){
                  if(value.length < 2){
                    return '客户姓名至少得2个字符啊';
                  }
                }
              });
          //监听提交
          form.on('submit(add)', function(data){
            console.log(JSON.stringify(data.field));
            //发异步，把数据提交给php
              $.ajax({
                  type:"POST",                      //请求类型
                  url:"./orderEdit?${item!=null?utils.Constants.postUpdate:utils.Constants.postAdd}",                 //URL
                  data:data.field,                  //传递的参数
                  dataType:"json",                 //返回的数据类型
                  success:function(data){          //data就是返回的json类型的数据
                      console.log(data);
                      layer.alert(data.msg, {icon: 6},function () {
                          parent.window.location.reload();
                      });
                  }
              });
            return false;
          });
        });
    </script>
